package cn.smartgarden.service.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.smartgarden.dao.ArgsDAO;
import cn.smartgarden.model.Args;
@Service
public class ArgsServiceImpl implements cn.smartgarden.service.ArgsService {

	@Autowired
	private ArgsDAO argdao;
	@Override
	public int insert(Args args) {
		// TODO Auto-generated method stub
		return argdao.insert(args);
	}

	@Override
	public List<Args> getAll() {
		// TODO Auto-generated method stub
		return argdao.getAll();
	}

	@Override
	public List<Args> getByDay(Date day) {
		// TODO Auto-generated method stub
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(day);
		String startday=df.format(cal.getTime());
		cal.add(Calendar.DAY_OF_MONTH, 1);
		String endday=df.format(cal.getTime());
		return argdao.getByDate(startday, endday);
	}

	@Override
	public List<Args> getByDate(String datestart, String dateend) {
		// TODO Auto-generated method stub
		return argdao.getByDate(datestart, dateend);
	}

	@Override
	public List<Args> getByDateSbh(Date day, String sbh) {
		// TODO Auto-generated method stub
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(day);
		String startday=df.format(cal.getTime());
		cal.add(Calendar.DAY_OF_MONTH, 1);
		String endday=df.format(cal.getTime());
		return argdao.getByDateSbh(startday, endday, sbh);
	}

	@Override
	public List<Map<String, Object>> getSbh() {
		// TODO Auto-generated method stub
		return argdao.getSbh();
	}

	@Override
	public List<Args> getLastRecord(int num, String sbh) {
		// TODO Auto-generated method stub
		return argdao.getLastRecord(num, sbh);
	}



}
